package com.action;


import com.token.JwtUtil;
import com.vo.ResponseBean;
import jdk.nashorn.internal.parser.Token;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@CrossOrigin("*")
@RequestMapping("/api/")
public class LoginAction {

    @RequestMapping("/login")
    public ResponseBean login(String username, String password, HttpServletResponse response) {
        if (username != null && username.equals(password)) {
            //登录成功，产生令牌，发送给客户端
            String token = JwtUtil.generToken(username,"","");

            //令牌域名（头子跨域)
            response.addHeader("Access-Control-Expose-Headers","token");
            response.addHeader("token", token);

            return new ResponseBean(200, 0, null);
        } else {
            return new ResponseBean(500, 0, null);
        }
    }
}
